package cn.edu.csust.cvs.management.utils;
/**
 * @Auther: snail
 * @Date: 2021/2/25 00:30
 * @Description: 时间工具类
 */
public class DateUtils {


    /**
     * 转换时间格式，“00:00:10.68” 转换成 秒数
     * @param durationString
     * @return
     */
    public static int convert(String durationString){
        int min=0;
        String strs[] = durationString.split(":");
        if (strs[0].compareTo("0") > 0) {
            min+=Integer.valueOf(strs[0])*60*60;//秒
        }
        if(strs[1].compareTo("0")>0){
            min+=Integer.valueOf(strs[1])*60;
        }
        if(strs[2].compareTo("0")>0){
            min+=Math.round(Float.valueOf(strs[2]));
        }
        return min;
    }


    /**
     * 转换时间格式， 描述 转换成 “00:00:10.68”
     * @param time
     * @return
     */
    public static String convert(double time){
        int min=0;
        String strs = "";
        strs += (time/60);
        strs += ":";
        strs += time%60;

        return strs;
    }

    public static String format(long runTime) {
        if(runTime < 0) return "00:00:00";

        long hour = runTime / 3600;
        long minute = (runTime % 3600) / 60;
        long second = runTime % 60;

        return unitTimeFormat(hour) + ":" + unitTimeFormat(minute) + ":" +
                unitTimeFormat(second);
    }

    private static String unitTimeFormat(long number) {
        return String.format("%02d", number);
    }

    public static void main(String[] args) {
        int seconds = convert("00:02:20");
        System.out.println(seconds);
        int ts = 160;
        String time = convert(ts);
        System.out.println(time);
    }
}
